#include "stdafx.h"
#include "wf_modifyrotate.h"

#include "pf_snapper.h"



WF_ModifyRotate::WF_ModifyRotate(PF_Container& container,
        PF_GraphicView& graphicView)
        :PF_PreviewActionInterface("Rotate Entities",
                           container, graphicView) {}


QAction* WF_ModifyRotate::createGUIAction(LX_Define::ActionType /*type*/, QObject* /*parent*/) {
	// tr("Rotate")
    QAction* action = new QAction(tr("&Rotate"), NULL);
	action->setIcon(QIcon(":/extui/modifyrotate.png"));
    //action->zetStatusTip(tr("Rotate Entities"));
    return action;
}

void WF_ModifyRotate::init(int status) {
    PF_ActionInterface::init(status);
}



void WF_ModifyRotate::trigger() {

    PF_DEBUG->print("PF_ActionModifyRotate::trigger()");

    PF_Modification m(*container, graphicView);
    m.rotate(data);

    PF_DIALOGFACTORY->updateSelectionWidget(container->countSelected());
}



void WF_ModifyRotate::mouseMoveEvent(PF_MouseEvent* e) {
    PF_DEBUG->print("PF_ActionModifyRotate::mouseMoveEvent begin");

    if (getStatus()==SetReferencePoint) {
        PF_Vector mouse = snapPoint(e);
        switch (getStatus()) {
        case SetReferencePoint:
            referencePoint = mouse;
            break;

        default:
            break;
        }
    }

    PF_DEBUG->print("PF_ActionModifyRotate::mouseMoveEvent end");
}



void WF_ModifyRotate::mouseReleaseEvent(PF_MouseEvent* e) {
    if (e->button()==Qt::LeftButton) {
        PF_CoordinateEvent ce(snapPoint(e));
        coordinateEvent(&ce);
    } else if (e->button()==Qt::RightButton) {
        deletePreview();
        init(getStatus()-1);
    }
}



void WF_ModifyRotate::coordinateEvent(PF_CoordinateEvent* e) {
    if (e==NULL) {
        return;
    }

    PF_Vector pos = e->getCoordinate();

    switch (getStatus()) {
    case SetReferencePoint:
        referencePoint = pos;
        setStatus(ShowDialog);
        if (PF_DIALOGFACTORY->requestRotateDialog(data)) {
            data.center = referencePoint;
            trigger();
            finish();
        }
        break;

    default:
        break;
    }
}



void WF_ModifyRotate::updateMouseButtonHints() {
    switch (getStatus()) {
    case SetReferencePoint:
        PF_DIALOGFACTORY->updateMouseWidget(tr("Specify reference point"),
                                            tr("Back"));
        break;
    default:
        PF_DIALOGFACTORY->updateMouseWidget("", "");
        break;
    }
}



void WF_ModifyRotate::updateMouseCursor() {
    graphicView->setMouseCursor(LX_Define::CadCursor);
}



void WF_ModifyRotate::updateToolBar() {
    switch (getStatus()) {
    case SetReferencePoint:
        PF_DIALOGFACTORY->requestToolBar(LX_Define::ToolBarSnap);
        break;
    default:
        PF_DIALOGFACTORY->requestToolBar(LX_Define::ToolBarModify);
        break;
    }
}


// EOF
